package com.antler.smt.admin.service.impl;

import com.antler.smt.admin.mapper.OrderCommentEntityMapper;
import com.antler.smt.entity.OrderCommentEntity;
import com.antler.smt.enums.ResultCodeEnum;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.admin.OrderCommentService;
import com.antler.smt.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 订单评价接口
 *
 * @author zhangyi
 * @date 2018/4/18 11:08
 */
@Service
public class OrderCommentServiceImpl implements OrderCommentService {


    @Autowired
    private OrderCommentEntityMapper orderCommentEntityMapper;

    /**
     * 修改首页标识字段
     *
     * @param id 订单评价id
     * @return
     */
    @Override
    public Result<ResultCodeEnum> OrderCommentHomePage(Long id) {
        Result result = null;

        //创建订单实体
        OrderCommentEntity orderCommentEntity = new OrderCommentEntity();

        //添加id
        orderCommentEntity.setId(id);

        //添加是否在首页展示 0否 1是
        orderCommentEntity.setShowToMainpage(1);

        //修改为有效
        orderCommentEntity.setStatus(1);

        //添加更新时间
        orderCommentEntity.setUpdateTime(DateUtil.stampToDate(System.currentTimeMillis()));

        int i = orderCommentEntityMapper.updateByPrimaryKeySelective(orderCommentEntity);

        if(0 == i){
            result = new Result(ResultCodeEnum.APPEND_DATA_ERROR);
        }else{
            result = new Result(ResultCodeEnum.OPERATION_SUCCESS);
        }

        return result;
    }

    /**
     *  修改服务商标识字段
     *
     * @param id 订单评价id
     * @return
     */
    @Override
    public Result<ResultCodeEnum> OrderCommentSupplier(Long id) {
        Result result = null;

        //创建订单实体
        OrderCommentEntity orderCommentEntity = new OrderCommentEntity();

        //添加id
        orderCommentEntity.setId(id);

        //是否向服务商展示0否 1是
        orderCommentEntity.setShowToSupplier(1);

        //修改为有效
        orderCommentEntity.setStatus(1);

        //添加更新时间
        orderCommentEntity.setUpdateTime(DateUtil.stampToDate(System.currentTimeMillis()));

        int i = orderCommentEntityMapper.updateByPrimaryKeySelective(orderCommentEntity);

        if(0 == i){
            result = new Result(ResultCodeEnum.APPEND_DATA_ERROR);
        }else{
            result = new Result(ResultCodeEnum.OPERATION_SUCCESS);
        }
        return result;
    }
}
